// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2005-4-30

#ifndef __CSUMPEIMAGE_H_COMMON_GUARD__
#define __CSUMPEIMAGE_H_COMMON_GUARD__

#pragma once

#include "csumpefile.h"

namespace JoyGuard
{

//##ModelId=44CF17BE03B9
class CSumPeImage
{
public:
	//##ModelId=44CF17BF001F
    enum ErrorCode
    {
		//##ModelId=44CF17BF0021
        EC_OK,
		//##ModelId=44CF17BF0022
        EC_FAILED,
		//##ModelId=44CF17BF0023
        EC_READ_MEMORY,
		//##ModelId=44CF17BF0024
        EC_CHECK_SUM,
    };
	//##ModelId=44CF17BF002E
    class ECheckStop : public std::exception
    {
    };

	//##ModelId=44CF17BE03BA
    volatile bool    m_stopped;
	//##ModelId=44CF17BE03C8
    DWORD   m_error;
	//##ModelId=44CF17BE03C9
    HANDLE  m_process;
	//##ModelId=44CF17BE03CA
    BYTE*   m_baseAddr;
	//##ModelId=44CF17BE03CC
    std::vector<BYTE>   m_tempBase;
	//##ModelId=44CF17BE03D0
    DWORD   m_readSize;
	//##ModelId=44CF17BE03D8
    DWORD   m_readDelay;
	//##ModelId=44CF17BE03D9
    DWORD   m_readed;
	//##ModelId=44CF17BE03DB
    CSumSect    m_csumSect;
	//##ModelId=44CF17BE03DF
    HANDLE  m_waitEvent;
	//##ModelId=44CF17BE03E1
    IMAGE_NT_HEADERS* m_ntHeaders;

	//##ModelId=44CF17BF0002
    void CheckStop();
	//##ModelId=44CF17BF0003
    void ReadMemory(BYTE* dst, BYTE* src, int len);
public:
	//##ModelId=44CF17BF0007
    CSumPeImage();

	//##ModelId=44CF17BF0008
    bool Create(HANDLE waitEvent, HANDLE hProcess, BYTE* baseAddr, const CSumSect& ss, DWORD readSize = 0, DWORD readDelay = 0);
	//##ModelId=44CF17BF0015
    void Close();
	//##ModelId=44CF17BF0016
    bool Check();
};

} // namespace JoyGuard

#endif  // __CSUMPEIMAGE_H_COMMON_GUARD__
